<?php

namespace App\Admin\Controllers;

use App\EloquentORM\ArticleLabel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Str;

class ArticleLabelController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '标签';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ArticleLabel);

        $grid->model()->orderBy('created_at','DESC');
//        $grid->column('id', __('ID'));
        $grid->column('name', __('名称'));
        $grid->column('color', __('颜色'));
        $grid->column('num', __('文章数量'));
        $grid->column('unique', __('随机数'));
//        $grid->column('created_at', __('Created at'));
//        $grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ArticleLabel::findOrFail($id));

//        $show->field('id', __('Id'));
        $show->field('name', __('名称'));
        $show->field('color', __('颜色'));
        $show->field('num', __('文章数量'));
        $show->field('unique', __('随机数'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ArticleLabel);

        $form->text('name', __('名称'));
        $form->color('color', __('颜色'));
//        $form->number('num', __('Num'));
        $form->hidden('unique', __('随机数'))->default(Str::uuid()->toString());

        return $form;
    }
}
